package com.yue.jersey.practice.provider;

import com.yue.jersey.practice.common.DatasUtils;
import com.yue.jersey.practice.model.CountryModel;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/12/2<br/>
 *
 * @author QiuYang
 */
@Service
public class DefaultCountryProvider implements CountryProvider {
    @Override
    public List<CountryModel> allCountries() {
        try {
            return DatasUtils.allCountries();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<CountryModel> updateCountriesWithSNames(List<String> snames) {
        try {
            List<CountryModel> models = DatasUtils.allCountries();

            return models.stream()
                    .filter(model -> snames.contains(model.getsName()))
                    .collect(Collectors.toList());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
